package com.cincc.cinccimdemo.viewholder;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cincc.cinccimdemo.R;
import com.cincc.cinccimdemo.adapter.ConversationAdapter;
import com.cincc.cinccimdemo.common.FileUtils;
import com.cincc.cinccimdemo.model.MessageInfoUI;
import com.cincc.im.model.enums.SendStatus;
import com.cincc.im.model.message.ImFileMessage;
import com.cincc.im.model.message.ImVideoMessage;

public class SendFileHolder extends MessageContentHolder {
    public ImageView iv_face;
    public ImageView iv_message;
    public TextView tv_filesize;
    public TextView tv_filename;
    public TextView tv_time;
    public ImageView iv_error;
    public ProgressBar pb_loading;
    public RelativeLayout rl_message;

    public SendFileHolder(Context context, View itemView, ConversationAdapter adapter) {
        super(context, itemView, adapter);
        iv_face = itemView.findViewById(R.id.iv_face);
        iv_message = itemView.findViewById(R.id.iv_message);
        tv_filesize = itemView.findViewById(R.id.filesize_text);
        tv_filename = itemView.findViewById(R.id.filename_text);
        tv_time = itemView.findViewById(R.id.tv_time);
        iv_error = itemView.findViewById(R.id.send_error_image);
        pb_loading = itemView.findViewById(R.id.progress);
        rl_message = itemView.findViewById(R.id.rl_message);
    }

    @Override
    public void bindView(MessageInfoUI uiMessage, int position) {
        super.bindView(uiMessage, position);
        ImFileMessage imFileMessage = (ImFileMessage) uiMessage.getMessageInfo().imMessage;

        String fileName = imFileMessage.fileName;
        String fileSize = FileUtils.getFileSize((int) imFileMessage.fileSize);
        tv_filename.setText(fileName);
        tv_filesize.setText(fileSize);
        iv_message.setImageResource(FileUtils.getFileTypeImageResId(fileName));
        pb_loading.setVisibility(uiMessage.getMessageStatus() == SendStatus.SEND_ING ? View.VISIBLE : View.GONE);
        rl_message.setOnClickListener(v -> {
            showFile(uiMessage);
        });
    }
}
